package com.yonyou.pmclouds.messagenotice.constructor.impl;

import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.entity.Entity;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.messagenotice.entity.MessageNoticeVO;
import com.yonyou.pmclouds.procedure.entity.ProcedureVO;
import com.yonyou.pmclouds.procedure.rmiitf.ProcedureQuery;
import com.yonyou.pmclouds.processphoto.entity.ProcessPhotoVO;
import com.yonyou.pmclouds.processphoto.rmiitf.ProcessPhotoQuery;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ProcessPhotoNoticeConstructor extends AbstractMessageNoticeConstructor {

    private final ProcessPhotoQuery processPhotoQuery;

    private final ProjectSimpleQuery projectSimpleQuery;

    private final ProcedureQuery procedureQuery;

    @Autowired
    public ProcessPhotoNoticeConstructor(ProcessPhotoQuery processPhotoQuery, ProjectSimpleQuery projectSimpleQuery,
                                         ProcedureQuery procedureQuery) {
        this.processPhotoQuery = processPhotoQuery;
        this.projectSimpleQuery = projectSimpleQuery;
        this.procedureQuery = procedureQuery;
    }


    @Override
    protected MessageNoticeVO[] generateContent(Entity vo) throws BusinessException {
        MessageNoticeVO noticeVO = coverBusinessVOToMessageVO(vo);
        if(noticeVO == null){
            return null;
        }
        // 您提交的【XX工序】的拍照记录已审批通过
        // 您提交的【XX工序】的报验申请已被驳回
        ProcessPhotoVO processPhotoVO = processPhotoQuery.queryOne(noticeVO.getRelateKey());
        ProjectVO projectVO = projectSimpleQuery.queryProject(processPhotoVO.getPk_project());
        ProcedureVO procedureVO = procedureQuery.getById(processPhotoVO.getPk_process());

        String procedureName = procedureVO.getSname() + "工序";
        String prefix = getApprovalPrefixMessage(processPhotoVO.getBillstatus());
        String messageContent = APPROVAL_PREFIX_MESSAGE + "[" + procedureName + "]" + "的拍照记录，" + prefix;

        noticeVO.setMessageTitle(projectVO.getSname());
        noticeVO.setMessageReceiver(processPhotoVO.getCreator());
        noticeVO.setPkTenant(processPhotoVO.getPk_tenant());
        noticeVO.setMessageContent(messageContent);
        noticeVO.setRelateType(processPhotoVO.getBill_type());

        return new MessageNoticeVO[]{noticeVO};
    }

    @Override
    public String getRelateType() {
        return BillTypeConst.PROCESSPHOTO_BILLTYPE;
    }
}
